package controller;

import model.StaffWholeDAO;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;

@Controller
public class StaffWholeAnalysis {

    @Autowired
    StaffWholeDAO staffDAO;

    @ResponseBody
    @RequestMapping(value="operator_count", produces = "text/html;charset=utf-8")
    public String operatorCount(@RequestParam(value="start", required=true) Timestamp start,
                                @RequestParam(value="end", required=true)Timestamp end,
                                @RequestParam(value="site", required=true) String site){
        String efficient = staffDAO.efficientAna(start, end, site);
        JSONObject eff = new JSONObject(efficient);
        JSONObject json = new JSONObject();
        json.put("张三", eff.getString("张三"));
        return json.toString();
    }

    @ResponseBody
    @RequestMapping(value="efficient_ana", produces = "text/html;charset=utf-8")
    public String efficientAna(@RequestParam(value="start", required=true) Timestamp start,
                                @RequestParam(value="end", required=true)Timestamp end,
                                @RequestParam(value="site", required=true) String site){
        String efficient = staffDAO.efficientAna(start, end, site);
        JSONObject eff = new JSONObject(efficient);
        JSONObject json = new JSONObject();
        json.put("张三", eff.getString("张三"));
        return json.toString();
    }

    @ResponseBody
    @RequestMapping(value="efficient_sort", produces = "text/html;charset=utf-8")
    public String efficientSort(@RequestParam(value="start", required=true) Timestamp start,
                               @RequestParam(value="end", required=true)Timestamp end,
                               @RequestParam(value="site", required=true) String site){
        String efficient = staffDAO.efficientAna(start, end, site);
        JSONObject eff = new JSONObject(efficient);
        JSONObject json = new JSONObject();
        json.put("张三", eff.getString("张三"));
        return json.toString();
    }
}
